package com.gu.qqdemo.frg;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.gu.qqdemo.Bean.FeatureBean;
import com.gu.qqdemo.MoreActivity;
import com.gu.qqdemo.R;
import com.gu.qqdemo.adapter.RvNewsAdapter;
import com.gu.qqdemo.dao.FeatureDao;
import com.gu.qqdemo.utils.app.BaseFragment;

import java.util.List;

public class MainFragment3 extends BaseFragment {
    private TextView tv3;
    private ImageView iv_head;
    private TextView tv_more;
    private RecyclerView rv;
    private RvNewsAdapter adapter;
    private List<FeatureBean> listData;
    private FeatureDao dao;
    private TextView tv_ad;

    @Override
    protected int getLayoutId() {
        return 0;
    }

    @Override
    protected View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container) {
        View view = inflater.inflate(R.layout.fragment_news, container, false);
        iv_head = view.findViewById(R.id.iv_head);
        tv_more = view.findViewById(R.id.tv_more);
        rv = view.findViewById(R.id.rv);
        tv_ad = view.findViewById(R.id.tv_ad);
        tv_ad.requestFocus();
        return view;
    }

    @Override
    protected void initData() {
        dao = new FeatureDao();
        listData = dao.findAllShow();
        adapter = new RvNewsAdapter(listData);
        rv.setLayoutManager(new LinearLayoutManager(act));
        rv.setAdapter(adapter);
    }

    @Override
    public void onResume() {
        super.onResume();
        listData.clear();
        adapter.notifyDataSetChanged();
        listData.addAll(dao.findAllOpen());
        adapter.notifyItemRangeInserted(0, listData.size());
    }

    @Override
    protected void initListener() {
        tv_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jumpToActivity(MoreActivity.class);
            }
        });
    }
}
